package com.baizhi.mapimpl;

import com.baizhi.homework.Student;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * map接口的实现类
 */
public class MapDemo04 {
    public static void main(String[] args) {
        //根据key升序排序
//
//        Map<Integer,String> map = new TreeMap<>();
//        map.put(1,"张三");
//        map.put(97,"李四");
//        map.put(15,"王五");
//        map.put(32,"赵六");
//
//
//
//        System.out.println(map);


        Map<Student,Integer> map = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });  //排序按照key排序
        map.put(new Student("李娜",18),88);
        map.put(new Student("白玉石",22),85);
        map.put(new Student("杨磊",26),36);
        map.put(new Student("安辉",29),25);
        map.put(new Student("祁波",21),0);

        System.out.println(map);
    }
}
